package com.trkj.service.lzs;


import java.math.BigDecimal;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.trkj.dao.lzs.RecruitprocessDao;
import com.trkj.dao.lzs.SalaryAccountDao;
import com.trkj.dao.lzs.SalarySableDao;
import com.trkj.pojo.ProjectTemplate;
import com.trkj.pojo.Recruitprocess;
import com.trkj.pojo.SalaryAccount;
import com.trkj.pojo.SocialSecurity;
import com.trkj.service.ServiceException;
import com.trkj.vo.Result;
import com.trkj.vo.payVO;
//薪资账套
@Service
@Transactional(rollbackFor = Exception.class)
public class Salaryservice {
	/*@Autowired
    private RecruitprocessDao recruitprocessDao ;*/
	@Autowired
	private SalaryAccountDao salaryAccountDao ;
	@Autowired
	private SalarySableDao projectTemplateDAO ;
      //查询所有
	public  List<SalaryAccount>  SalaryAccount1(){
		
	   return (List<SalaryAccount>) salaryAccountDao.findAll();
		
	}
	//根据姓名查找
	  //模糊查询
		//根据姓名查找
		public  List<SalaryAccount> queryByName (String  text){

			return salaryAccountDao.queryByName("%" + text + "%");
		}
	//分页
     public  List<SalaryAccount>fenye (int page, int  rows){
		return salaryAccountDao.queryByPage(new PageRequest(page - 1, rows));
		
     }	
   //记录数
     public  Long SalaryAccountByPageCount(){
		return salaryAccountDao.count();
    	 
     }
     
     
	 /*  //招聘查询所有
		public  List<Recruitprocess>  Recruitprocess1(){
			
		   return (List<Recruitprocess>) recruitprocessDao.findAll();
			
		}*/
	/*//添加
	public void  wan(long reproId, String reproName,String reproPerson) {
	try {
			Recruitprocess ab= new Recruitprocess() ;
		    ab.setReproId(reproId);
			ab.setReproName(reproName);
			ab.setReproPerson(reproPerson);
			recruitprocessDao.save(ab);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		
//	}
     
     //编辑  
     public   void lzs_Edit( Long accountId, String accountName,
    		 BigDecimal accountNumber,String accountPerson,String accountRemark,Timestamp accountStartdate ,Timestamp accountEnddate ,Timestamp accountCreatordate) {
    	    SalaryAccount edit =salaryAccountDao.findOne(accountId);
    	    edit.setAccountName(accountName);
    	    edit.setAccountNumber(accountNumber);
    	    edit.setAccountPerson(accountPerson);
    	    edit.setAccountRemark(accountRemark);
    	    edit.setAccountEnddate(accountEnddate);
    	    edit.setAccountStartdate(accountStartdate);
    	   edit.setAccountCreatordate(accountCreatordate);
    	    salaryAccountDao.save(edit);
     }
     
     public SalaryAccount chun(Long accountId) {
    	 SalaryAccount attr =salaryAccountDao.findOne(accountId);
 		return attr;
     }
     //多表查询
     public List<payVO> selcet_SalaryAccount(){
 		List<payVO> vo = new ArrayList();
 		List<Object[]> obj= salaryAccountDao.find_pay();
 		for (Object[] objects : obj) {
 			payVO vof = new payVO();
 			
 			SalaryAccount s  = (SalaryAccount) objects[0];
 			ProjectTemplate p  = (ProjectTemplate) objects[1];
 			if(p!=null){
 				vof.setTemplateName(p.getTemplateName());
 			}
 				vof.setAccountId(s.getAccountId());
 				vof.setAccountName(s.getAccountName());
 				vof.setAccountNumber(s.getAccountNumber());
 				vof.setAccountStartdate(s.getAccountStartdate());
 				vof.setAccountEnddate(s.getAccountEnddate());
 				vof.setAccountPerson(s.getAccountPerson());
 				vof.setAccountCreatordate(s.getAccountCreatordate());
 				vof.setTemplateId(p.getTemplateId());
 				vo.add(vof);
 		}
 		return vo;
 	}
//多表增加
     public void add_SalaryAccount(SalaryAccount s,Long templateId){
 		try {
 			ProjectTemplate p = projectTemplateDAO.findOne(templateId);
 			s.setProjectTemplate(p);
 			salaryAccountDao.save(s);
 		} catch (Exception e) {
 			e.printStackTrace();
 			throw new ServiceException(e);
 		}
 	}
 //删除
     public boolean dltRa(Long accountId) {
 		if(salaryAccountDao.exists(accountId)){
 			salaryAccountDao.delete(accountId);
 			 return true;
 		}
 		return false;
 	}
     
     
}
